package com.framework.base.aqs;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author chaolong.jin
 * @description
 * @date 2019/08/24 10:04
 */
public class PoolTest {


    public static void main(String[] args) throws InterruptedException {
        final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(3, 10, 0, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
        List<Callable<Void>> runnableList=new ArrayList<>();
        for(int i=0;i<10;i++)
        {
            runnableList.add(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    System.out.println("invoke " +"runing  "+threadPoolExecutor.getActiveCount()+"  queue  "+threadPoolExecutor.getQueue().size());
                    return null;
                }
            });
        }
        threadPoolExecutor.invokeAll(runnableList);
//        List<Callable<Void>> runnableList2=new ArrayList<>();
//        Thread.sleep(1000);
//        for(int i=0;i<4;i++)
//        {
//            runnableList2.add(new Callable<Void>() {
//
//                @Override
//                public Void call() throws Exception {
//                    System.out.println("invoke 2" +"runing  "+threadPoolExecutor.getActiveCount()+"  queue  "+threadPoolExecutor.getQueue().size());
//                    return null;
//                }
//            });
//        }
//        threadPoolExecutor.invokeAll(runnableList2);
    }
}
